package com.zhonghan.recharge.service.impl;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhonghan.common.bean.Result;
import com.zhonghan.common.enums.ResultStatus;
import com.zhonghan.common.utils.StringUtils;
import com.zhonghan.recharge.dao.ZhBusinessGascardOrderDao;
import com.zhonghan.recharge.pojo.ZhBusinessGascardOrder;
import com.zhonghan.recharge.pojo.ZhBusinessUser;
import com.zhonghan.recharge.service.ZhBusinessGascardOrderService;
@Service
public class ZhBusinessGascardOrderServiceImpl implements ZhBusinessGascardOrderService{
    @Autowired
    private ZhBusinessGascardOrderDao zhBusinessGascardOrderDao;
    @Override
    public long getZhBusinessGascardOrderRowCount(){
        return zhBusinessGascardOrderDao.getZhBusinessGascardOrderRowCount();
    }
    @Override
    public List<ZhBusinessGascardOrder> selectZhBusinessGascardOrder(){
        return zhBusinessGascardOrderDao.selectZhBusinessGascardOrder();
    }
    @Override
    public List<ZhBusinessGascardOrder> selectZhBusinessGascardOrderByObj(ZhBusinessGascardOrder obj){
        return zhBusinessGascardOrderDao.selectZhBusinessGascardOrderByObj(obj);
    }
    @Override
    public ZhBusinessGascardOrder selectZhBusinessGascardOrderById(Integer id){
        return zhBusinessGascardOrderDao.selectZhBusinessGascardOrderById(id);
    }
    @Override
    public int insertZhBusinessGascardOrder(ZhBusinessGascardOrder value){
        return zhBusinessGascardOrderDao.insertZhBusinessGascardOrder(value);
    }
    @Override
    public int insertNonEmptyZhBusinessGascardOrder(ZhBusinessGascardOrder value){
        return zhBusinessGascardOrderDao.insertNonEmptyZhBusinessGascardOrder(value);
    }
    @Override
    public int insertZhBusinessGascardOrderByBatch(List<ZhBusinessGascardOrder> value){
        return zhBusinessGascardOrderDao.insertZhBusinessGascardOrderByBatch(value);
    }
    @Override
    public int deleteZhBusinessGascardOrderById(Integer id){
        return zhBusinessGascardOrderDao.deleteZhBusinessGascardOrderById(id);
    }
    @Override
    public int updateZhBusinessGascardOrderById(ZhBusinessGascardOrder enti){
        return zhBusinessGascardOrderDao.updateZhBusinessGascardOrderById(enti);
    }
    @Override
    public int updateNonEmptyZhBusinessGascardOrderById(ZhBusinessGascardOrder enti){
        return zhBusinessGascardOrderDao.updateNonEmptyZhBusinessGascardOrderById(enti);
    }

    public ZhBusinessGascardOrderDao getZhBusinessGascardOrderDao() {
        return this.zhBusinessGascardOrderDao;
    }

    public void setZhBusinessGascardOrderDao(ZhBusinessGascardOrderDao zhBusinessGascardOrderDao) {
        this.zhBusinessGascardOrderDao = zhBusinessGascardOrderDao;
    }

    /**
     * 查询订单
     */
    public Result selectZhBusinessGascardOrderByCondition(Long userId,String orderNo,String gascardNo,String telephone,String fillCardSequence,
    		String rechargeState,String beginTime,String endTime,String orderType, Integer pageNum,Integer pageSize){
    	
    	pageNum = pageNum == null ? 0 : pageNum;
    	pageSize = pageSize == null ? 0 : pageSize;
    	
    	ZhBusinessGascardOrder order = new ZhBusinessGascardOrder();
		if(userId != null){
			order.setBusinessId(userId);
		}
		if(StringUtils.isNotEmpty(orderNo)){
			order.setOrderNo(orderNo);
		}
		if(StringUtils.isNotEmpty(gascardNo)){
			order.setGascardNo(gascardNo);
		}
		if(StringUtils.isNotEmpty(telephone)){
			order.setTelephone(telephone);
		}
		if(StringUtils.isNotEmpty(fillCardSequence)){
			order.setFillCardSequence(fillCardSequence);
		}
		if(StringUtils.isNotEmpty(rechargeState)){
			order.setRechargeState(rechargeState);
		}
		if(StringUtils.isNotEmpty(beginTime)){
			order.setBeginTime(beginTime);
		}
		if(StringUtils.isNotEmpty(endTime)){
			order.setEndTime(endTime);
		}
		if(StringUtils.isNotEmpty(orderType)){
			order.setOrderType(orderType);
		}
		order.setOrderBy("orderTime");
		order.setSortBy("desc");
		
		Result result = new Result();
		try {
			
			PageHelper.startPage(pageNum, pageSize);
			List<ZhBusinessGascardOrder> orderList = zhBusinessGascardOrderDao.selectZhGascardOrderByCondition(order);
			PageInfo<ZhBusinessGascardOrder> pageInfo = new PageInfo<>(orderList);
			result.setCode(ResultStatus.SUCCESS.getCode());
			result.setData(pageInfo);
			
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(ResultStatus.BUSYNESS.getCode());
			result.setMsg(ResultStatus.BUSYNESS.getDescription());
		}
    	
    	return result;
    }
    
    @Override
	public Result getOrderDetail(String orderNo) {
		Result result = new Result();
		try {
			ZhBusinessGascardOrder order = zhBusinessGascardOrderDao.selectZhBusinessGascardOrderByOrderNo(orderNo);
			
			if(order != null){
				result.setCode(ResultStatus.SUCCESS.getCode());
				result.setData(order);
			}else{
				result.setCode(ResultStatus.FAILURE.getCode());
				result.getMsg();
			}
			
		} catch (Exception e) {
			result.setCode(ResultStatus.BUSYNESS.getCode());
			result.setMsg(ResultStatus.BUSYNESS.getDescription());
			e.printStackTrace();
		}
		return result;
	}
	@Override
	public long getZhBusinessGascardOrderRowCountByObj(ZhBusinessGascardOrder order) {
		
		long rows = zhBusinessGascardOrderDao.getZhBusinessGascardOrderRowCountByObj(order);
		
		return rows;
	}
	@Override
	public Long selectBusinessSaleAmountByObj(ZhBusinessGascardOrder order) {
		return zhBusinessGascardOrderDao.selectBusinessSaleAmountByObj(order);
	}
}